import Vue from 'vue'
import Vuex from 'vuex'
import area from '@/utils/area.js'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userInfo: '',
    ISLOGIN: false
    // userInfo: {}
  },
  mutations: {
    // 修改登录状态
    SETLOGIN (state) {
      state.ISLOGIN = false
    },
    // 修改用户信息
    SETUSERINFO (state, newuserinfo) {
      state.userInfo = newuserinfo
    },
    // 修改用户某个值
    SETUSERSOME (state, { key, value }) {
      state.userInfo[key] = value
    }
  },
  getters: {
    // 获取性别
    userGender (state) {
      const genderObj = {
        0: '未知',
        1: '男',
        2: '女'
      }
      return genderObj[state.userInfo.gender]
    },
    // 城市信息
    userArea (state) {
      if (state.userInfo) {
        return area.city_list[state.userInfo.area]
      }
      return ''
    }
  }
})
